export default {
	namespaced:true,
	state:()=>({
		// 
			token:JSON.parse(uni.getStorageSync('token') || '{}'),
			address:JSON.parse(uni.getStorageSync('address') || '{}'),
			userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
			redirection:null
	}),
	mutations:{
		// 更新收货地址
		updateAddress(state,address) {
			state.address = address
			this.commit('m_user/saveAddressStorage')
		},
		// 更新用户信息
		updateUserInfo(state,userinfo) {
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfoStorage')
		},
		// 更新token
		updateToken(state,token) {
			state.token = token
			this.commit('m_user/saveToken')
		},
		// 持久化存储
		saveAddressStorage(state) {
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		saveUserInfoStorage(state) {
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		saveToken(state) {
			uni.setStorageSync('token',JSON.stringify(state.token))
		},
		updateRedirect(state,info) {
			state.redirection = info
		},
	},
	getters:{
		// 收货地址
		addStr(state) {
			if (!state.address.provinceName) return ''
			// 拼接 省，市，区，详细地址 的字符串并返回给用户
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address
				.detailInfo
		}
	}
}